//package com.whyx.project.openapi.controller;
//
//import com.alibaba.dubbo.config.annotation.Reference;
//
//import com.bootdo.common.utils.R;
//import com.whyx.project.openapi.config.KafkaProducerConfig;
//import com.whyx.project.user.service.RedisService;
//import com.whyx.project.user.service.WebApi;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiImplicitParam;
//import io.swagger.annotations.ApiImplicitParams;
//import io.swagger.annotations.ApiOperation;
//import org.apache.kafka.clients.consumer.ConsumerRecord;
//import org.apache.log4j.Logger;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.kafka.annotation.KafkaListener;
//import org.springframework.kafka.support.Acknowledgment;
//import org.springframework.web.bind.annotation.*;
//import javax.servlet.http.HttpServletRequest;
//
//import java.util.List;
//
//
//@RestController
//@Api(description = "前端接口")
//public class WebController extends BaseController {
//    public final Logger log = Logger.getLogger(WebController.class);
//    @Reference
//    private WebApi webApi;
//
//    @Reference
//    public RedisService redisService;
//
//    @Autowired
//    KafkaProducerConfig kafkaProducerConfig;
//
//    @ApiOperation("电子围栏")
//    @CrossOrigin //允许跨域认证
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "controllerPath", paramType = "path", allowableValues = "web", required = true),
//            @ApiImplicitParam(name = "id", value = "电子围栏id", dataType = "int", paramType = "query")
//    })
//    @PostMapping(value = "/{controllerPath}/getElectricFence")
//    public @ResponseBody
//    R getElectricFence(HttpServletRequest request) throws Exception {
//        R r = new R();
////        webApi.getAllElectricFence().forEach(electricFenceDO -> {
////            redisService.set(electricFenceDO.getId().toString(), JSONObject.toJSONString(electricFenceDO), RedisService.MIN * 60);
////        });
////
////        log.info(" redis value:  " + redisService.get(request.getParameter("id")));
////
////        try {
////            r.put("code", "0");
////            r.put("msg", webApi.getElectricFence(Long.parseLong(request.getParameter("id"))));
////            return r;
////        } catch (Exception e) {
////            r.put("code", "1");
////            r.put("msg", e.getMessage());
////            return r;
////        } finally {
////            return r;
////        }
//
//        return r;
//    }
//
//    @ApiOperation("写入kafka操作")
//    @CrossOrigin //允许跨域认证
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "controllerPath", paramType = "path", allowableValues = "web", required = true)
//    })
//    @PostMapping(value = "/{controllerPath}/setDataToKafka/{data}")
//    public @ResponseBody R setDataToKafka(@PathVariable("data") String data) throws Exception {
//        R r = new R();
//        kafkaProducerConfig.kafkaTemplate().send("linkStatus", data);
//        try {
//            r.put("code", "0");
//            r.put("msg", data);
//            return r;
//        } catch (Exception e) {
//            r.put("code", "1");
//            r.put("msg", e.getMessage());
//            return r;
//        } finally {
//            return r;
//        }
//    }
//
//    //kafka消费处理
//    @KafkaListener(topics = "linkStatus",containerFactory = "GpsAlarmFactory")
//    public void channelLinkStatusConsumerListen(List<ConsumerRecord<?, ?>> records, Acknowledgment ack) {
//        try {
//            for (ConsumerRecord<?, ?> record : records) {
//                String msg = record.value().toString();
//                System.out.println("Received: " + msg);
//            }
//
//        } catch (Throwable e) {
//            e.printStackTrace();
//        }
//    }
//
//
//
//
//}
